import { toLogin } from '@/api/login.js'
import { Message } from 'element-ui'
import { setTokena, getTokena } from '@/utils/save'
const state = {
  token: '' || getTokena()
}

const mutations = {
  setToken (state, value) {
    state.token = value
  }
}

const actions = {
  async tolayout ({ commit }, value) {
    const res = await toLogin(value)
    commit('setToken', res.data.data.token)
    setTokena(res.data.data.token)
    console.log(res)
    if (res.data.code !== 202) {
      Message.success('登录成功')
    } else {
      Message.error(res.data.message + '错误')
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
